package com.xea.service;

import java.util.List;


import com.uf.util.SqlHelper;
import com.xea.model.Others;
public class OthersService {
	
	/**
	 * 查询其它
	 * @param type       类别
	 * @return
	 */
	public List<Others> search(int type){
		
		String sql = "select * from Others where type = ? order by id";
		return SqlHelper.query(sql, new Object[]{type}, Others.class);
		
	}
	
	/**
	 * 新增类别
	 * @param news   新闻实体
	 * @return
	 */
	public void add(Others others){
		
		String sql = "insert into Others(type,pub,content) values(?,?,?)";
		Object[] params=new Object[]{others.getType(),others.getPub(),others.getContent()};
		SqlHelper.excute(sql, params);
		
	}
	
	/**
	 * 类别详情
	 * @param id  id 
	 * @return
	 */
	public Others findById(int id){
		
		String sql = "select * from Others where id = ?";		
		List<Others> list = SqlHelper.query(sql, new Object[]{ id}, Others.class);
		if(list == null || list.isEmpty()){
			return null;
		}
		return list.get(0);
		
	}
	
	/**
	 * 查询其它公开
	 * @param type  类别 
	 * @return
	 */
	public Others findByIdPub(int type){
		
		String sql = "select * from Others where pub=1 and type = ?";		
		List<Others> list = SqlHelper.query(sql, new Object[]{ type}, Others.class);
		if(list == null || list.isEmpty()){
			return null;
		}
		return list.get(0);
		
	}
	
	/**
	 * 删除类别
	 * @param id   id
	 * @return
	 */
	public void del(String id){
		
		String sql = "delete from Others where id in("+id+")";
		SqlHelper.excute(sql, null);
		
	}
	
	/**
	 * 修改是否公开
	 * @param id   id
	 * @param pub   是否公开
	 * @return
	 */
	public void pub(String id,int pub){
		String sql = "update Others set pub=? where id in("+id+")";
		Object[] params=new Object[]{pub};
		SqlHelper.excute(sql, params);
		
	}
	
	/**
	 * 取消公开
	 * @param type   类别
	 * @return
	 */
	public void notpub(int type){
		
		SqlHelper.excute("update Others set pub=0 where type="+type, null);

	}
	
	/**
	 * 修改Others
	 * @param others   Others实体
	 * @return
	 */
	public void update(Others others){
		
		String sql = "update Others set content=?,pub=? where id=?";
		Object[] params=new Object[]{others.getContent(),others.getPub(),others.getId()};
		SqlHelper.excute(sql, params);
		
	}
}
